#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_reportGenerator = new ReportGenerator(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_btnPreview_clicked()
{
    //进行导出PDF的预览显示
    auto res = m_reportGenerator->outPreview();
    if(res.count() == 0) return;
    ui->labPreview->setText("");
    ui->labPreview->setAlignment(Qt::AlignCenter);
    ui->labPreview->setPixmap(
                QPixmap::fromImage(res.at(0).toImage().
                                   scaledToWidth(ui->labPreview->width(), Qt::SmoothTransformation)));
}

void MainWindow::on_btnExport_clicked()
{
    m_reportGenerator->generateReport(QDir::currentPath() + "/测试报告.pdf");
    return;

    QString filename = QFileDialog::getSaveFileName(this,
                                                    "保存PDF报告",
                                                    QDir::currentPath() + "/测试报告.pdf",
                                                    "PDF文件 (*.pdf)");

    if (filename.isEmpty()) return;

    if (!filename.endsWith(".pdf", Qt::CaseInsensitive)) {
        filename += ".pdf";
    }

    m_reportGenerator->generateReport(filename);

    // 显示成功消息
    QMessageBox::information(this, "报告生成成功",
                             "测试报告已成功生成！\n文件名: " + filename);
}
